(function (factory) {
  // Packaging/modules magic dance
  var L;
  if (typeof define === 'function' && define.amd) {
    // AMD
    define(['leaflet'], factory);
  } else if (typeof module !== 'undefined') {
    // Node/CommonJS
    L = require('leaflet');
    module.exports = factory(L);
  } else {
    // Browser globals
    if (typeof window.L === 'undefined') {
      throw new Error('Leaflet must be loaded first');
    }
    factory(window.L);
  }
}(function (L) {
  'use strict';

  L.Control.Mapclear = (function () {

    var Mapclear = L.Control.extend({
      options: {
        position: 'topright',
        _divedit:null,
        _divcont:null,
        _amarker:null,
        _apolyline:null,
        _acircle:null,
        _arect:null,
        _apolygon:null,
        _aenddraw:null,
        _acleardrawlayer:null,
        _aclose:null
      },
      //初始化参数
      initialize: function (options) {
        L.Util.extend(this.options, options);
      },
      onAdd: function (map) {
        this._map = map;
        //创建一个class为leaflet-control-clegend的div，作用整体容器，可以同 this._container.appendChild 向此容器中添加任何内容
        this._container = L.DomUtil.create('div', 'leaflet-control-mapclear');

        //创建自己的内容
        this._divcont=L.DomUtil.create('div', 'leaflet-draw-control-edit-div');
        this._divcont.style="width:29px;height:29px;border:2px solid #889ebe; background-color:#ffffff;text-align:center;vertical-align:middle;";
        this._divedivimg=L.DomUtil.create('img', 'leaflet-draw-control-edit-div-img',this._divcont);
        this._divedivimg.style="width:17px;height:19px;margin-top:3px;background-image:url('/static/js/draw-lib/images/mapclear.png')";
        L.DomEvent.addListener(this._divcont, 'click', this.Mapclearclick, this);
        this._container.appendChild(this._divcont);

        //返回
        return this._container;
      },
      onRemove: function (map) {

      },
      Mapclearclick:function () {
        this._map.fire('onMapClearClick', {});
      }
    });

    return Mapclear;
  })();

  L.control.mapclear = function (options) {
    return new L.Control.Mapclear(options);
  };
}));
